/*
   @Copyright:LeetCode
   @Author:   tjyemail
   @Problem:  http://leetcode.com/problems/decode-ways
   @Language: C++
   @Datetime: 19-07-09 15:55
   */

class Solution {
public:
	int numDecodings(string &s) {
		if(s.length()==0 || s.find("00")!=s.npos) return 0;
		int pp=0, p=1, cur=s[0]>'0'?1:0;
		for(int i=1, num=0; i<s.length(); ++i){
			pp=p, p=cur, cur=s[i]>'0'?p:0;
			num=(s[i-1]-'0')*10+s[i]-'0';
			if(num>26 && s[i]=='0') return 0;
			if(num>9 && num<27) cur+=pp;
		}
		return cur;
	}
};
